<template>
  <div id="login">
    <div class="rightContain">
      <div class="inputContain">
        <div class="chooseLogin"></div>
        <div style="margin: 0; padding-top: 25px; padding-right: 25px">
          <el-form
            size="medium"
            :model="ruleForm"
            status-icon
            :rules="rules"
            label-width="80px"
            ref="ruleForm"
            id="ruleForm"
          >
            <el-form-item label="用户名" prop="username" class="title">
              <el-input v-model.trim="ruleForm.username" autofocus></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password" class="title">
              <el-input
                type="password"
                v-model.trim="ruleForm.password"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                style="width: 100%"
                size="medium"
                @keyup.enter="submitForm()"
                @click="submitForm('ruleForm')"
                type="primary"
                >登录
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Api from "@/http/apis/modules/uses.js";
import callCenter from "@/config/callCenter.js";
export default {
  data() {
    return {
      blue: 1, //当为1时，新系统登录下面的横杠显示，为0时，旧系统下的横杠显示
      account: null,
      password: null,
      loading: false,
      isshow: false,
      ruleForm: {
        username: null,
        password: null,
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    clickBtn() {
      document.getElementById("btn1").oncontextmenu = function (e) {
        e.preventDefault();
      };
      //在这里你就可以自己定义事件的函数啦
      document.getElementById("btn1").onmouseup = function (oEvent) {
        if (!oEvent) oEvent = window.event;
        if (oEvent.button == 2) {
          console.log("鼠标右击了");
          console.log("x: ", oEvent.clientX, " y:", oEvent.clientY);
        }
      };
    },
    getMousePos(event) {
      var e = event || window.event;
      return { x: e.clientX, y: clientY };
    },
    newLogin() {
      this.blue = 1;
    },
    oldLogin() {
      this.blue = 0;
    },
    submitForm() {
      const _this = this;
      // 控制遮罩
      _this.isshow = this.loading = true;
      if (_this.blue === 0) {
        _this.$router.push("/OldUser");
      }
      Api.LoginApi({
        userAccount: _this.ruleForm.username,
        userPassword: _this.ruleForm.password,
      }).then((res) => {
        _this.isshow = this.loading = false;
        if (res.data.code === "SUCCESS") {
          console.log(
            "呼叫中心",
            res.data.result.user.ccipAdress,
            res.data.result.user.companyId,
            "坐席号：",
            res.data.result.user.seatsId,
            "密码：",
            res.data.result.user.telPassword
          );
          if (res.data.result.user.ccipAdress != null) {
            callCenter.onReady(
              res.data.result.user.ccipAdress,
              res.data.result.user.companyId,
              res.data.result.user.seatsId,
              res.data.result.user.telPassword
            );
          }
          // 保存用户信息
          localStorage.setItem(
            "userInfo",
            JSON.stringify(res.data.result.user)
          );
          localStorage.setItem(
            "depart",
            JSON.stringify(res.data.result.depart)
          );
          // this.$store.commit("userInfo", [
          //   res.data.result.token,
          //   res.data.result.token,
          // ]);
          /**=======================存储在SessionStorage中的登陆者数据======================================== */
          // 权限信息/个人信息
          this.$store.commit("ROLEMENU", [
            res.data.result.authority,
            res.data.result.button,
            res.data.result.token,
            res.data.result.user,
            res.data.result.depart,
          ]);
          sessionStorage.setItem("binding", res.data.result.token);
          //跳转到首页：首页权限99，排在第一个
          if (this.$store.state.roleMenu[0].path == "") {
            _this.$router.push(this.$store.state.roleMenu[0].children[0].path);
          } else {
            _this.$router.push(
              `${this.$store.state.roleMenu[0].path}/${this.$store.state.roleMenu[0].children[0].path}`
            );
          }
          sessionStorage.setItem(
            "homePath",
            this.$store.state.roleMenu[0].children[0].path
          );
        } else {
          this.$message({
            message: "账号或密码错误",
            type: "error",
          });
        }
      });
    },
  },
  created() {
    this.$store.commit("CLEARTOPMENUS");
    // 回车触发搜索事件
    var that = this;
    document.onkeydown = function (e) {
      var key = window.event.keyCode;
      if (key === 13) {
        that.submitForm(); // 触发事件
      }
    };
  },
};
</script>
<style lang="less" scoped>
#login {
  width: 100%;
  height: 100%;
  position: relative;
  background: url(../assets/imgs/login.jpg);
  background-size: 100% 100%;
}
#login .bgc {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  img {
    width: 100%;
    height: 100%;
  }
}
#login .rightContain {
  width: 30%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0; /* 四周拉力相同 */
  right: 0; /* 四周拉力相同 */
  bottom: 0; /* 四周拉力相同 */
  left: 0; /* 四周拉力相同 */
  margin: auto; /* 再设置 marign 自动 */
}
#login .inputContain {
  width: 80%;
  height: 45%;
}
#login .chooseLogin {
  width: 100%;
  height: 35px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin: 0;
  padding: 0;
}
#login .newLogin {
  cursor: pointer;
  height: 100%;
  line-height: 35px;
  padding: 0;
  margin-left: 30px;
  color: #fff;
}
#login .oldLogin {
  cursor: pointer;
  width: 50px;
  height: 100%;
  line-height: 35px;
  margin-right: 170px;
}
#login .passWord {
  width: 100%;
  height: 100%;
  text-align: left !important;
  margin-top: 25px;
  margin-bottom: 20px;
}
#login .layui-input {
  width: 300px;
  height: 30px;
}
#login #password {
  margin-top: 15px;
  margin-bottom: 10px;
}
#login .layui-input-block {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
#login .layui-btn {
  width: 300px;
  height: 40px;
  background-color: skyblue;
}
#login .el-icon-user-solid {
  position: absolute;
  top: 10px !important;
  clear: both;
}
#login .el-input__prefix {
  position: absolute;
  top: 10px !important;
}
/deep/.el-form .title .el-form-item__content {
  margin-top: 5px;
  .el-input__inner {
    background-color: rgba(245, 246, 248, 0.8);
  }
}
/deep/.el-form {
  .el-form-item__label {
    color: #fff;
  }
}
// .abi {
//   text-align: center;
//   a {
//     color: #fff;
//     text-decoration: none;
//   }
// }
</style>

